package com.foreknow.web;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.foreknow.entity.HisSytem;
import com.foreknow.service.HisSytemService;
import com.foreknow.utils.Constance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/hissytemcontroller")
public class HisSytemController {

    @Autowired
    private HisSytemService hisSytemService;

    @RequestMapping(value = "/selectHis", method = RequestMethod.GET)

    public String selectHis() throws JsonProcessingException {
        List<HisSytem> list = hisSytemService.selectHis();
        HashMap<String, Object> hs = new HashMap<>();
        if (list != null) {
            hs.put("data", list);
            hs.put("meta", new Constance("msg", 200));
        } else {
            hs.put("meta", new Constance("msg", 404));
        }
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.writeValueAsString(hs);
    }
}
